package com.surpassun.emall.service.impl;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.surpassun.emall.model.City;
import com.surpassun.emall.repository.CityRepository;
import com.surpassun.emall.service.CityService;
import com.surpassun.emall.service.StatisticsService;
import com.surpassun.emall.util.Constants;
import com.surpassun.emall.util.GetterUtil;
import com.surpassun.emall.util.PropsKeys;
import com.surpassun.emall.util.PropsUtil;
import com.surpassun.emall.util.Validator;

/**
 *
 * @author Denis
 */
@Service
public class CityServiceImpl extends AbstractServiceImpl<City> implements CityService {

	@Inject
	CityRepository cityRepository;
	
	@Inject
	StatisticsService statisticsService;
	
	public CityServiceImpl() {
    	super(City.class);
    }
	
	@Override
	public List<City> getPopularCities() {
		int number = GetterUtil.getInteger(PropsUtil.getString(PropsKeys.SELECT_POPULAR_CITIES_NUMBER));
		List<Long> referenceIds = statisticsService.getTopItems(Constants.STATISTICS_TYPE_CITY, number);
		if (Validator.isNotEmpty(referenceIds)) {
			return cityRepository.getPopularCities(referenceIds);
		} else {
			return null;
		}
	}
}